package exp07gui.mvc;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * java swing的一种MVC编程模式
 * <p>
 * Controller 层耦合了Model 和View需要从View获得数据，然后送给Model计算然后传给View更新视图
 */
public class Controller implements ActionListener {
    View view = null;
    Model model = null;

    Controller() {
        view = new View();
        model = new Model();
        view.jButtonEqual.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == view.jButtonEqual) {
            System.err.println("1111111111111111");
            int a = Integer.parseInt(view.jTextFieldA.getText());
            int b = Integer.parseInt(view.jTextFieldB.getText());
            model.setA(a);
            model.setB(b);
            model.calculate();
            System.out.println("aaaaaa");
            view.jLabelResult.setText(model.getC() + "_");
        }

    }
}